package com.xiao.consumer.controller;

import com.xiao.provider.clients.UserClients;
import com.xiao.provider.vo.reqvo.UserReqVo;
import com.xiao.provider.vo.resvo.UserResVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @Description 服务消费者控制器，调用服务提供者提供的接口
 * @Auther: 笑笑是一个码农
 * @Date: 17:05 2020/12/23
 */
@RestController
public class UserController {

    @Resource
    private UserClients userClients;

    /**
     * 添加用户接口
     * @param userReqVo
     */
    @PostMapping(value = "/v1/consumer/user")
    public void addUser(@RequestBody @Validated UserReqVo userReqVo){
        userClients.addUser(userReqVo);
    }

    /**
     * 查询用户接口
     * @param id
     * @return
     */
    @GetMapping(value = "/v1/consumer/user/{id}")
    public UserResVo getUser(@PathVariable("id") Long id){
        return userClients.getUser(id);
    }

    /**
     * 修改用户接口
     * @param id
     * @param userReqVo
     */
    @PutMapping(value = "/v1/consumer/user/{id}")
    public void updateUser(@PathVariable("id") Long id, @RequestBody @Validated UserReqVo userReqVo){
        userClients.updateUser(id, userReqVo);
    }

    /**
     * 删除用户接口
     * @param id
     */
    @DeleteMapping(value = "/v1/consumer/user/{id}")
    public void deleteUser(@PathVariable("id") Long id){
        userClients.deleteUser(id);
    }
}
